home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / os2 / mus2v131.zip / PlySong.cmd < prev    next >
OS/2 REXX Batch file  |  1996-02-08  |  4KB  |  119 lines

  1. /* ########################################################################
  2.  
  3.    This REXX script will communicate with a running Module Player that
  4.    support a Command Pipe.
  5.  
  6.    The Following commands are used
  7.       Query Song  -- Returns three lines, first is the file name, second is the
  8.                      index and third is the song title. They represent
  9.                      the currently playing song.
  10.       Play Song -- Searches the song list for the given substring match,
  11.                    first one is played and the name and index are returned.
  12.  
  13.    ########################################################################
  14. */
  15. '@echo off'                       /* Don't echo commands */
  16. say " Module Player Song Changer V1.0                                          Ethos"
  17.    call OpenPlayer
  18.    if Result <> 0 then do
  19.       say "Error" Error
  20.       return
  21.    end
  22.  
  23.    if CallPlayer("Query","Song","") <> 0 then do
  24.       say "Error" Error
  25.       return
  26.    end
  27.    Say "Currently Playing Song" Result.1 "'" || Result.3 || "'"
  28.  
  29.    if (arg(1) = '') then do
  30.       say "Require a substring to match in the songlist."
  31.       return
  32.    end
  33.  
  34.    if CallPlayer("Play","Song",arg(1)) <> 0 then do
  35.       say "Error" Error
  36.       return
  37.    end
  38.    Say "Jumped to" Result.2
  39.  
  40. return
  41.  
  42. /* ########################################################################
  43.  
  44.    Function - CallPlayer
  45.    Eg - if (CallPlayer("Query","Song","") <> 0) then Error
  46.  
  47.    Description - This procedure sends a command message to the player.
  48.                  An error is returned if the player doesn't understand
  49.                  the message or something else is wrong.
  50.                    Result - A stem containing each line of the result
  51.                    Error - Global error code
  52.  
  53.    ########################################################################
  54. */
  55. CallPlayer: procedure expose Result. Player Error
  56.    parse arg Command, SCommand, Arg
  57.  
  58.    Error = ""
  59.    Result.0 = 0
  60.  
  61.    /* Player not loaded */
  62.    if (Player = "") then do
  63.       Error = "Player not Inited"
  64.       return 1
  65.    end
  66.  
  67.    call lineout Player,Command SCommand Arg
  68.  
  69.    /* Get all the results */
  70.    do while (1)
  71.       Line = linein(Player)
  72.  
  73.       /* Error or something */
  74.       if (pos("!!",Line) = 1) then do
  75.          if (Line = "!! OK") then
  76.             return 0
  77.          Error = substr(Line,4)
  78.          return 1
  79.       end;
  80.  
  81.       Result.0 = Result.0 + 1
  82.       I = Result.0
  83.       Result.I = Line
  84.    end
  85.  
  86. return 0
  87.  
  88. /* ########################################################################
  89.  
  90.    Function - OpenPlayer
  91.    Eg - call OpenPlayer
  92.  
  93.    Description - This procedure opens the pipe and sets the following:
  94.                    Player - The name of the pipe - \pipe\Player
  95.                    Version - The pipe comminication version
  96.                    Type - The program running on the other end, 'Text UI'
  97.                    Error - Global Error Code
  98.  
  99.    ########################################################################
  100. */
  101. OpenPlayer:procedure expose Player Version Type Error
  102.    Error = ""
  103.  
  104.    Result = Stream("\pipe\ModulePlayer","C","OPEN");
  105.    if (Result <> "READY:") then do
  106.       Error = "Unable to communicate with the  Player, is it running?"
  107.       Player = ""
  108.       return 1
  109.    end
  110.    Player = "\pipe\ModulePlayer"
  111.  
  112.    /* Get the version */
  113.    S = linein(Player)
  114.    parse var S 'V' Version .
  115.    Type = linein(Player)
  116. return 0
  117.  
  118.  
  119.